package TankWar;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TankGameJFrame extends JFrame implements ActionListener {

    // 游戏面板
    private MyJPanel gamePanel;
    // 开始按钮
    private JButton startButton;
    // 暂停按钮
    private JButton pauseButton;
    // 得分标签
    private JLabel scoreLabel;
    // 生命值标签
    private JLabel lifeLabel;

    public TankGameJFrame() {
        // 创建游戏窗口
        setTitle("坦克大战");
        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        // 初始化游戏面板
        gamePanel = new MyJPanel();

        // 初始化得分标签
        scoreLabel = new JLabel("得分: 0");
        scoreLabel.setFont(new Font("仿宋体", Font.BOLD, 30));
        scoreLabel.setForeground(Color.red);

        // 初始化生命值标签
        lifeLabel = new JLabel("生命值: 3");
        lifeLabel.setFont(new Font("仿宋体", Font.BOLD, 30));
        lifeLabel.setForeground(Color.red);

        // 初始化开始按钮
        startButton = new JButton("开始");
        startButton.setFont(new Font("仿宋体", Font.BOLD, 25));
        startButton.addActionListener(this);

        // 初始化暂停按钮
        pauseButton = new JButton("暂停");
        pauseButton.setFont(new Font("仿宋体", Font.BOLD, 25));
        pauseButton.addActionListener(this);

        // 设置布局
        setLayout(new BorderLayout());
        add(gamePanel, BorderLayout.CENTER);

        JPanel controlPanel = new JPanel();
        controlPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
        controlPanel.add(startButton);
        controlPanel.add(pauseButton);
        controlPanel.add(scoreLabel);
        controlPanel.add(lifeLabel);

        add(controlPanel, BorderLayout.SOUTH);

        setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == startButton) {
            // 开始游戏逻辑
            gamePanel.startGame();
        } else if (e.getSource() == pauseButton) {
            // 暂停游戏逻辑
            gamePanel.pauseGame();
        }
    }

    public static void main(String[] args) {
        new TankGameJFrame();
    }
}
